﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EasyMvc.Web.Common;
using System.Web.Mvc;
using EasyMvc.Config;

namespace EasyMvc.Web.Areas.MWeb.Controllers
{
    [Permission(EnumViewPermission.ManageConfig)]
    public class ConfigController : MWebControllerBase
    {
        #region Actions
        public ActionResult Index()
        {    
            return View();
        }

        public ActionResult EditSetting()
        {
            var config = this.ConfigContext.Get<Setting>();
            return View(config);
        }

        [HttpPost]
        public ActionResult EditSetting(FormCollection collection)
        {
            var config = this.ConfigContext.Get<Setting>();
            this.TryUpdateModel<Setting>(config);

            this.ConfigContext.Save<Setting>(config);

            return this.RefreshParent();
        }
        #endregion
    }
}
